package cat.joronya.supermanager.team;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import cat.joronya.supermanager.R;

/**
 * Activity to make changes using drag'n'drop based on images.
 */
@TargetApi(16)
public class MyTeamDashboardActivity extends ActionBarActivity
{
	public static final String TAG = "supermanager";
	
	@Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	super.onCreate(savedInstanceState);
    	
    	// set the layout for content view
        setContentView(R.layout.dashboard_layout);
        
        // definim el home button per tirar enrera
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        //getSupportActionBar().setHomeButtonEnabled(true);
        
    	// guardem id equip i jornada
        final long idequ = getIntent().getLongExtra("cat.joronya.supermanager.myteams.idequ",0);
        final int day = getIntent().getIntExtra("cat.joronya.supermanager.myteams.day",0);
    	
    	// setejem el fragment q toca
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                       .replace(R.id.fragment, MyTeamDashboardCourtFragment.newInstance(idequ,day))
                       .replace(R.id.fragment_favorites, MyTeamDashboardListFragment.newInstance(day))
                       .commit();
        
        // titol de la pantalla home inicalment
        setTitle(getResources().getString(R.string.dashboard_title));
    }
	
	@Override
	protected void onNewIntent(Intent intent) 
	{
		super.onNewIntent(intent);
	}
    
	@Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
		// Handle item selection
        switch( item.getItemId() ) 
        {
        	// Respond to the action bar's Up/Home button
        	case android.R.id.home:
        		Intent upIntent = NavUtils.getParentActivityIntent(this);
        		long idequ = getIntent().getLongExtra("cat.joronya.supermanager.myteams.idequ",0);
        		upIntent.putExtra("cat.joronya.supermanager.myteams.idequ", idequ);
                NavUtils.navigateUpTo(this, upIntent);
        		return true;
        		
        	default:
        		return super.onOptionsItemSelected(item);
        }
    }
}
